Vendor acquisition-sdk instead of depending on the code-push npm package - #9
Conversation
61e7e38 to
3779b2e
Compare
bbc0ffc to
de0b597
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (13)
🚧 Files skipped from review as they are similar to previous changes (13)
WalkthroughAdded a vendored TypeScript Acquisition SDK with update checks, status reporting, HTTP handling, validation, and CodePush-specific errors. Added mock-backed SDK tests. Updated TypeScript build configuration and package scripts to emit 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (5)
src/acquisition-sdk/__tests__/acquisition-sdk.test.ts (1)
266-266: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the duplicated assignment.
acquisition = acquisition = new ...assigns twice.🧹 Proposed fix
- acquisition = acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.CustomResponseHttpRequester(invalidJsonResponse), configuration); + acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.CustomResponseHttpRequester(invalidJsonResponse), configuration);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/acquisition-sdk/__tests__/acquisition-sdk.test.ts` at line 266, Remove the duplicated assignment in the AcquisitionManager setup so the acquisition variable is assigned to the new AcquisitionManager instance only once.src/acquisition-sdk/acquisition-sdk.ts (2)
216-216: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace the
arguments-based callback reassignment.This line assigns
falsetocallbackwhen the last argument is not a function, which contradicts the declaredCallback<void>type and relies onargumentsinside a class method. The declaredcallbackparameter already carries the value. Removing the line keeps behavior for all documented call shapes and improves readability.♻️ Proposed refactor
- callback = typeof arguments[arguments.length - 1] === "function" && arguments[arguments.length - 1]; - this._httpRequester.request(Http.Verb.POST, url, JSON.stringify(body), (error: Error, response: Http.Response): void => {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/acquisition-sdk/acquisition-sdk.ts` at line 216, Remove the arguments-based reassignment of callback in the acquisition method, keeping the declared callback parameter unchanged. Preserve the existing handling for all documented call shapes without introducing a false value or relying on arguments.
143-145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPass an explicit
nullerror instead of the outererrorvariable.The
erroridentifier here resolves to the requester callback parameter from Line 117, which is already known to be falsy. Thecatchbinding at Line 138 is not in scope. The current code reads as if it forwards a parse error, but it always reports "no update". Make the intent explicit.♻️ Proposed refactor
if (!updateInfo) { - callback(error, /*remotePackage=*/ null); + callback(/*error=*/ null, /*remotePackage=*/ null); return;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/acquisition-sdk/acquisition-sdk.ts` around lines 143 - 145, Update the !updateInfo branch in the acquisition request callback to pass an explicit null error to callback, preserving the null remotePackage argument and early return. Do not use the outer error parameter, since this path represents no available update rather than a parsing failure.src/acquisition-sdk/__tests__/acquisition-rest-mock.ts (2)
76-89: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Server.onAcquireis dead code.No caller references
onAcquire. It also uses field names that no longer match the SDK contract (params.deploymentKey,isAvailable), so it would mislead a future reader who wires these tests into a runner. Consider removing it during the port.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/acquisition-sdk/__tests__/acquisition-rest-mock.ts` around lines 76 - 89, Remove the unused Server.onAcquire method from the acquisition REST mock; no callers reference it, and its outdated deploymentKey/isAvailable contract should not remain as misleading dead code.
9-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMutable module-level exports depend on CommonJS output.
Tests reassign
mockApi.serverUrlandmockApi.latestPackagethrough a namespace import. That works with CommonJS emit, but native ES modules make namespace properties read-only, so the assignment throws in strict mode. If the future test runner uses native ESM, replace theseexport varbindings with exported setter functions.As per path instructions, tests under
src/acquisition-sdk/__tests__/are reference tests and are not wired into a runner yet, so this is a note for the runner work rather than a blocker.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/acquisition-sdk/__tests__/acquisition-rest-mock.ts` around lines 9 - 32, Replace the mutable module-level exports serverUrl and latestPackage with exported setter functions, and update test consumers to call those setters instead of reassigning namespace-import properties. Preserve the existing mock state and ensure updateMockUrl continues rebuilding URLs from the current server URL.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.npmignore:
- Around line 37-41: Add /tsconfig.build.json to the root .npmignore alongside
/src/ so tsconfig.build.json is excluded from published packages. Verify with
npm pack --dry-run that tsconfig.build.json is absent while compiled lib/ files
remain included.
In `@src/acquisition-sdk/__tests__/acquisition-sdk.test.ts`:
- Around line 148-149: Update the acquisition SDK test setup so each test
receives a clean configuration: reset or recreate the module-level configuration
in beforeEach alongside mockApi, and remove the unused companionAppConfiguration
clone. In the test around the App Center serverUrl case, mutate the per-test
configuration rather than rebinding the shared object, ensuring ignoreAppVersion
and serverUrl changes cannot leak into later tests.
In `@src/acquisition-sdk/acquisition-sdk.ts`:
- Around line 96-100: Guard the optional callback before invoking it on the
_apiCallsDisabled paths in all three public methods, including
reportStatusDeploy and reportStatusDownload. Preserve the existing null
arguments and early returns, while matching the guarded callback behavior
already used by the response handlers.
---
Nitpick comments:
In `@src/acquisition-sdk/__tests__/acquisition-rest-mock.ts`:
- Around line 76-89: Remove the unused Server.onAcquire method from the
acquisition REST mock; no callers reference it, and its outdated
deploymentKey/isAvailable contract should not remain as misleading dead code.
- Around line 9-32: Replace the mutable module-level exports serverUrl and
latestPackage with exported setter functions, and update test consumers to call
those setters instead of reassigning namespace-import properties. Preserve the
existing mock state and ensure updateMockUrl continues rebuilding URLs from the
current server URL.
In `@src/acquisition-sdk/__tests__/acquisition-sdk.test.ts`:
- Line 266: Remove the duplicated assignment in the AcquisitionManager setup so
the acquisition variable is assigned to the new AcquisitionManager instance only
once.
In `@src/acquisition-sdk/acquisition-sdk.ts`:
- Line 216: Remove the arguments-based reassignment of callback in the
acquisition method, keeping the declared callback parameter unchanged. Preserve
the existing handling for all documented call shapes without introducing a false
value or relying on arguments.
- Around line 143-145: Update the !updateInfo branch in the acquisition request
callback to pass an explicit null error to callback, preserving the null
remotePackage argument and early return. Do not use the outer error parameter,
since this path represents no available update rather than a parsing failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e52e6725-579b-441d-a9f3-8bdb2c40d80b
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (13)
.gitignore.npmignoreCLAUDE.mdCodePush.jspackage.jsonrequest-fetch-adapter.jssrc/acquisition-sdk/__tests__/acquisition-rest-mock.tssrc/acquisition-sdk/__tests__/acquisition-sdk.test.tssrc/acquisition-sdk/acquisition-sdk.tssrc/acquisition-sdk/code-push-error.tssrc/acquisition-sdk/types.tstsconfig.build.jsontsconfig.json
There was a problem hiding this comment.
Pull request overview
This PR vendors the CodePush acquisition-sdk (server-communication layer) into this repository and adds a dedicated TypeScript build pipeline (src/ → lib/) so the runtime can consume the SDK without depending on the archived code-push npm package and its transitive dependency chain.
Changes:
- Vendored
acquisition-sdkTypeScript sources intosrc/acquisition-sdk/(types, errors, acquisition manager). - Added a separate TS build config (
tsconfig.build.json) and npm scripts (build:ts,prepare) to generate publishable runtime output underlib/. - Updated runtime wiring to consume the vendored SDK (
CodePush.jsimport change) and removed theX-CodePush-SDK-Versionheader.
Reviewed changes
Copilot reviewed 11 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tsconfig.json |
Excludes src/ from the integration-test TypeScript compile unit and documents the split. |
tsconfig.build.json |
New TS config to compile vendored runtime TS (src/) to publishable JS/typings (lib/). |
src/acquisition-sdk/types.ts |
Adds vendored request/response types for the acquisition client. |
src/acquisition-sdk/code-push-error.ts |
Adds vendored error types used by the acquisition SDK. |
src/acquisition-sdk/acquisition-sdk.ts |
Adds the vendored acquisition manager implementation and HTTP abstractions. |
src/acquisition-sdk/__tests__/acquisition-sdk.test.ts |
Ports upstream unit tests (kept as reference; not wired into a runner). |
src/acquisition-sdk/__tests__/acquisition-rest-mock.ts |
Ports upstream mock HTTP requester/server helpers for the tests. |
request-fetch-adapter.js |
Drops X-CodePush-SDK-Version and updates the enum-sync reference. |
package.json |
Adds build:ts and hooks it into setup/prepare; removes code-push dependency. |
package-lock.json |
Removes code-push and its dependency chain from the lockfile. |
CodePush.js |
Switches acquisition SDK import to the compiled vendored output under lib/. |
CLAUDE.md |
Documents the new build:ts workflow and notes about unit test infra. |
.npmignore |
Prevents publishing TypeScript source (/src/) and excludes local dev tooling docs. |
.gitignore |
Ignores generated lib/ output (built during prepare). |
Suppressed comments (1)
src/acquisition-sdk/acquisition-sdk.ts:242
- When API calls are disabled,
reportStatusDownloadinvokescallbackunconditionally even though it is optional, which can throw if a caller omits it.
if (AcquisitionManager._apiCallsDisabled) {
console.log(`[CodePush] Api calls are disabled, skipping API call`);
callback(/*error*/ null, /*not used*/ null);
return;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds src/acquisition-sdk/ (vendored TypeScript from the archived microsoft/code-push repo, trimmed types.ts to only what's used, tests ported for future reference but not wired into any runner), a tsconfig.build.json + build:ts script compiling it to lib/ at prepack/setup time, and points CodePush.js at the compiled output instead of the code-push package. Drops the code-push dependency entirely, which was only ever used for this one submodule and pulled in the superagent/proxy-agent/vm2 CLI dependency chain that never actually shipped in the bundled app JS.
de0b597 to
98c82dd
Compare
Summary
Vendors the
acquisition-sdk(server-communication layer) directly into this repo instead of depending on the archivedcode-pushnpm package, dropping that package and itssuperagent/proxy-agent/vm2dependency chain entirely.Decisions
Drop
X-CodePush-SDK-Versionheader, only reportX-CodePush-Plugin-Version: we are okay with it on the server side, the version of theacquisition-sdkis not relevant, especially after vendoring it.Vendor relevant files 1:1, do not fix bugs or make refactors.
Vendor relevant test files too, without running them: we still don't have a proper unit test setup in this project (only E2E tests), and I think that's outside the scope of this PR. Once we set up unit testing, these vendored tests become runnable.
Since
acquisition-sdkis written in TS, and the runtime part of CodePush is still in JS, this PR introduces a TS -> JS transpilation step (build:tsNPM script). Alternatives considered:acquisition-sdkto JS and vendor that: this would go against our plans to convert JS in this repo to TS.js,.d.tsand.js.mapfiles) into git: too easy to forget to do it after code changes.This transpilation is hooked into NPM's
preparescript.prepareruns at bothnpm installandnpm publish(unlike theprepackhook). This ensures a consistent dir layout with the right generated JS files in both the local env and in CI.This build split is intentionally temporary:
tsconfig.build.json(forsrc/→lib/) exists separately fromtsconfig.json(fortest/→bin/) only becauseacquisition-sdkis the sole part of the runtime migrated to TypeScript so far. OnceCodePush.jsand the rest of the runtime JS move to TS, these should collapse into one build — and adopting a common tool likereact-native-builder-bobinstead of hand-rolledtsc+ npm script wiring is worth reconsidering at that point.